import request from '@/utils/http'
import type { FileItemModel } from '@/api/file'
export interface UserLoginSendModel {
  phone: string | number
  password: string
  captcha: string
}
/** 用户登录
 */
export function userLogin(data: UserLoginSendModel) {
  return request<string>({
    url: '/user/login',
    method: 'post',
    data,
    noNeedToken: true,
  })
}

export interface userGetuserInfoReturnModel {
  id: number
  userName: string
  phone: string
  email: string
  avatar: FileItemModel[]
  password: string
  descText: string
  addressName: string
  province: string
  city: string
  county: string
  addressDetail: string
  createTime: number
  updateTime: number
  lastLoginTime: number
  rate_count: string

  role?: string[] // 项目角色权限所需，暂不需要动态设定
}
/** 获得用户信息
 */
export function userGetuserInfo() {
  return request<userGetuserInfoReturnModel>({
    url: '/user/getInfo',
    method: 'get',
  })
}

/** 刷新token */
export function userRefreshToken() {
  return request<string>({
    url: '/user/refreshToken',
    method: 'get',
  })
}

interface UserModifyAccountSendModel {
  type: string
  phone: string
  email: string
  newEmail: string
  password: string
  code: string
  [propName: string]: any
}
/** 根据类型修改用户的手机号、绑定邮箱、密码 */
export function userModifyAccount(data: UserModifyAccountSendModel) {
  return request({
    url: '/user/modifyAccount',
    method: 'post',
    data,
  })
}

interface UserModifySendModel {
  userName?: string
  avatar?: string | number
  descText?: string
  addressName?: string
  province?: string
  city?: string
  county?: string
  addressDetail?: string
}
/** 修改用户信息（传什么字段修改什么） */
export function userModify(data: UserModifySendModel) {
  return request({
    url: '/user/modify',
    method: 'post',
    data,
  })
}
